package com.hgkx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hgkx.domain.Visitors;
import com.hgkx.mapper.VisitorsMapper;
import com.hgkx.service.IVisitorsService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author jiangwen
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class VisitorsServiceImpl extends ServiceImpl<VisitorsMapper, Visitors> implements IVisitorsService {

    @Override
    public List<Visitors> queryAllVisitorsList(Visitors visitors) {
        QueryWrapper<Visitors> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(visitors.getVisitorsId())) {
            queryWrapper.eq("visitors_id", visitors.getVisitorsId());
        }
        if (StringUtils.isNotEmpty(visitors.getName())) {
            queryWrapper.like("name", visitors.getName());
        }
        if (StringUtils.isNotEmpty(visitors.getPhone())) {
            queryWrapper.eq("phone", visitors.getPhone());

        }
        queryWrapper.orderByAsc("create_time");
        return this.list(queryWrapper);
    }

    @Override
    public void saveVisitors(Visitors visitors) {
        this.baseMapper.insert(visitors);
    }


}
